﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Rapor.KoliIrsaliye
{
    public partial class KoliIrsaliye : DevExpress.XtraReports.UI.XtraReport
    {
        int  IrsaliyeNo;
        DateTime SevkTarihi;
        string Details;
        
        public KoliIrsaliye()
        {
            InitializeComponent();
        }

        public KoliIrsaliye(string _irsaliyeNo, DateTime sevkTarihi, string details, int _userId, int _tip, int _destination, string _cikanPartiIds, string _teslimEden, int _irsaliyeId)
            : this()
        {
            IrsaliyeNo = Convert.ToInt32(_irsaliyeNo);
            SevkTarihi = sevkTarihi;
            Details = details;
            tcTeslimEden.Text = _teslimEden;

            if (_irsaliyeId > 0)
                myDataKumas.Merge(Session.DataManager.ExecuteDataSet("GetKumasIrsaliyeByIrsaliyeId", _irsaliyeNo, sevkTarihi, details, _irsaliyeId, _userId, _tip, _destination, _cikanPartiIds));
            else
                myDataKumas.Merge(Session.DataManager.ExecuteDataSet("GetKoliIrsaliyeByCikisPartiId", _irsaliyeNo, sevkTarihi, details, _userId, _tip, _destination, _cikanPartiIds));

            myDataKumas.KumasIrsaliye.Merge(myDataKumas.Tables["Table"]);
            myDataKumas.KumasIrsaliyeLines.Merge(myDataKumas.Tables["Table1"]);

            KoliIrsaliyeLines KoliIrsaliyeLines1 = (KoliIrsaliyeLines)xrSubreport1.ReportSource;
            KoliIrsaliyeLines1.fillTables(myDataKumas.KumasIrsaliyeLines);
        }

        void xrTableCell32_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            int factor;

            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            if (this.ReportUnit == ReportUnit.HundredthsOfAnInch)
            {
                gr.PageUnit = GraphicsUnit.Inch;
                factor = 100;
            }
            else
            {
                gr.PageUnit = GraphicsUnit.Millimeter;
                factor = 10;
            }

            SizeF size = gr.MeasureString(((XRLabel)sender).Text, ((XRLabel)sender).Font);


            if (((XRLabel)sender).Width < size.Width * factor)
                ((XRLabel)sender).Font = new System.Drawing.Font("Microsoft Sans Serif", ((XRLabel)sender).Font.Size * ((XRLabel)sender).Width / size.Width / factor * 1.025F);

            gr.Dispose();
        }

        private void xrSubreport1_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ((KoliIrsaliyeLines)((XRSubreport)sender).ReportSource).TalepID.Value =
       Convert.ToInt32(GetCurrentColumnValue("KumasCikisTalebiId"));
        }

    }
}
